﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Styx;
using Styx.Common;
using Styx.Pathing;
using Styx.Plugins;

namespace ImprovedNavigator
{
    public class ImpNav : HBPlugin
    {
        public override void Pulse()
        {
        }

        public override string Name
        {
            get { return "Imp Nav 1.0"; }
        }

        public override string Author
        {
            get { return "Inrego"; }
        }

        public override Version Version
        {
            get { return new Version(1,0);}
        }
        public override void Initialize()
        {
            var oldNavigator = Navigator.NavigationProvider;
            var newNavigator = new ImpNavProvider(oldNavigator);
            Navigator.NavigationProvider = newNavigator;
            Logging.Write("[Imp. Nav] Old navigation has been overridden.");
        }
    }
    public class ImpNavProvider : MeshNavigator
    {
        private static INavigationProvider _oldNav;
        public ImpNavProvider(INavigationProvider oldNav)
        {
            if (_oldNav == null)
                _oldNav = oldNav;
        }
        public new MoveResult MoveTo(WoWPoint location)
        {
            if (_oldNav.CanNavigateFully(StyxWoW.Me.Location, location, 8192))
                return _oldNav.MoveTo(location);
            else
            {
                if (StyxWoW.Me.Location.Distance(location) > PathPrecision)
                {
                    Flightor.MoveTo(location);
                    return MoveResult.Moved;
                }
                else
                {
                    return MoveResult.ReachedDestination;
                }
            }
        }
    }
}
